class Solution {
public:
    int shipWithinDays(vector<int>& weights, int days) {
       vector<int> a=weights;
       sort(a.begin(),a.end());
       int lt=a[a.size()-1];
       int rt=0;
       for(int i=0;i<a.size();i++ ){
        rt=rt+a[i];
       }
       while(lt<rt){
        int mid=(lt+rt)/2;
        int cur=0,day=1;
        for(int i=0;i<a.size();i++){
            if(cur+weights[i]>mid){
                day++;
                cur=0;
            }
            cur=cur+weights[i];
        }
        if(day<=days){
            rt=mid;
        }
        else{
            lt=mid+1;
        }
       }
       return lt;
    }
};
